﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MaymuseMS.Models;
using MaymuseMS.Models.ValueObject;

namespace MaymuseMS.DAL {
    public class SemifinishedDepositoryRepository : GenericRepository<SemifinishedDepository> {
        public SemifinishedDepositoryRepository(MaymuseMSContext context)
            : base(context) {

        }

        //public void Increase(ProductValueObject productValueObject, int count, string location) {
        //    var semifinishedDepository = Get(productValueObject.Number);
        //    if (semifinishedDepository == null) {
        //        semifinishedDepository = new SemifinishedDepository {
        //            ProductValueObject = productValueObject, Total = 0, Location = ""
        //        };
        //        this.Add(semifinishedDepository);
        //    }

        //    semifinishedDepository.Total += count;

        //    if (!string.IsNullOrWhiteSpace(location) &&
        //        !semifinishedDepository.Location.Contains(location)) {
        //        if (!string.IsNullOrWhiteSpace(semifinishedDepository.Location)) {
        //            semifinishedDepository.Location += (", " + location);
        //        } else {
        //            semifinishedDepository.Location += (location);
        //        }
        //    }
        //}

        //public void Reduce(string number, int count) {
        //    var semifinishedDepository = Get(number);
        //    if (semifinishedDepository != null) {
        //        semifinishedDepository.Total -= count;
        //    }
        //}

        public SemifinishedDepository Get(string number) {
            var semifinishedDepository = this.dbSet.Where(p => p.ProductValueObject.Number == number).FirstOrDefault();
            return semifinishedDepository;
        }
    }
}